import axios from 'axios'
import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const state={
    count:0,
    price:999,
    movieList:[]
}

const mutations = {
    increment(state){
        state.count++
    },
    decrement(state,{n}){
        state.price -=n
    },
    getMovieList(state,movieList){
        state.movieList = movieList
    }
    
}

const actions={
    incrementWait({commit}){
        setTimeout(()=>{
            commit('increment')
        },2000)
    },

    async getMovieList({commit}){
        const result = await axios.get('https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a')
        commit('getMovieList',result.data.data.list)
    }
       
}

export default new Vuex.Store({
    state,
    mutations,
    actions
})